package com.bd.scm.module.system.controller;


import cn.hutool.core.util.ObjectUtil;
import com.bd.scm.domain.dto.system.ColumnDto;
import com.bd.scm.domain.models.leave.KtQingj;
import com.bd.scm.domain.models.system.BdSysProcDesc;
import com.bd.scm.module.common.BaseController;
import com.bd.scm.module.enums.ExceptionEmun;
import com.bd.scm.module.exception.ScmException;
import com.bd.scm.module.system.IBdSysProcDescService;
import com.bd.scm.module.system.KtQingjService;
import com.bd.scm.module.utils.ResultUtil;
import com.bd.utils.vo.Result;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author yufc
 * @since 2019-12-06
 */
@RestController
@RequestMapping("/api/sys")
@Slf4j
@Api(tags = "系统设置接口")
@ApiSort(value = 99)
public class BdSysProcDescController extends BaseController {

    @Resource
    private IBdSysProcDescService iBdSysProcDescService;

    @Resource
    private KtQingjService ktQingjService;

    @GetMapping("columns")
    @ApiOperation(value = "根据类型ID获取字段信息", httpMethod = "GET", protocols = "HTTP", notes = "根据类型ID获取字段信息", produces = "application/json")
    @ApiOperationSupport(order = 1)
    public Result getColumnsByClassId(
            @ApiParam(name = "classId", value = "类型ID", required = true, defaultValue = "0")
            @RequestParam(name = "classId", defaultValue = "0") int classId) {

        List<ColumnDto> colList = iBdSysProcDescService.getColumnsByClassId(classId);

        if (CollectionUtils.isEmpty(colList)) {
            return ResultUtil.error(ExceptionEmun.SERVICE_ERROR_NODATA.getMsg());
        }

        return ResultUtil.ok(colList);
    }


    @GetMapping("columns/schedule")
    @ApiOperation(value = "根据年月获取排班列数据", httpMethod = "GET", protocols = "HTTP", notes = "根据年月获取排班列数据", produces = "application/json")
    @ApiOperationSupport(order = 2)
    public Result getColumnsSchedule(
            @ApiParam(name = "year", value = "年份", required = true, defaultValue = "0")
            @RequestParam(name = "year", defaultValue = "0") int year,
            @ApiParam(name = "month", value = "月份", required = true, defaultValue = "0")
            @RequestParam(name = "month", defaultValue = "0") int month) {

        List<ColumnDto> colList = iBdSysProcDescService.getColumnsSchedule(year, month);

        return ResultUtil.ok(colList);
    }

    /**
     * 根据申请类型获取假类
     * 1：个人申请   2：批量申请
     *
     * @return
     */
    @GetMapping("base/leaveType")
    @ApiOperation(value = "获取请假假类数据", httpMethod = "GET", protocols = "HTTP", notes = "获取请假假类数据", produces = "application/json")
    @ApiOperationSupport(order = 3)
    public Result getLeaveType(
            @ApiParam(name = "applyType", value = "申请类型  1：个人申请   2：批量申请", required = true, defaultValue = "1")
            @RequestParam(value = "applyType") int applyType) {

        if (ObjectUtil.isEmpty(applyType)) {
            throw new ScmException((ExceptionEmun.SERVICE_ERROR_PARAMS));
        }

        if (1 != applyType && 2 != applyType) {
            throw new ScmException(ExceptionEmun.SERVICE_ERROR_PARAMS);
        }

        List<KtQingj> list = ktQingjService.getLeaveType(applyType);

        return ResultUtil.ok(list);
    }

}
